package com.xgg.taiwuinfo.filter.fc;

import android.util.Log;

import com.xgg.taiwuinfo.filter.FC_SelectCompareNum;
import com.xgg.taiwuinfo.filter.FilterComponent;
import com.xgg.taiwuinfo.gongfa.abilities.Ability_Cuipo_Damage;
import com.xgg.taiwuinfo.gongfa.base.Gongfa;
import com.xgg.taiwuinfo.gongfa.base.Gongfa_Cuipo;
import com.xgg.taiwuinfo.utils.GongfaType;

import org.json.JSONObject;

import java.util.ArrayList;

public class FCCuipoDamageCompareNum extends FC_SelectCompareNum {
    public FCCuipoDamageCompareNum(JSONObject obj)
    {
        mTypeId = FilterComponent.FT_DAMAGE_COMPARE_NUM;
        if (obj != null) {
            try {
                ReadField = obj.getInt("f");
                ReadCompare = obj.getInt("c");
                ReadValue = obj.getString("v");
            } catch (Exception e) {
                Log.d("LoadJson", e.getLocalizedMessage());
                ReadField = 0;
                ReadCompare = FC_GREATER;
                ReadValue = "0";
            }
        }
        else {
            ReadField = 0;
            ReadCompare = FC_GREATER;
            ReadValue = "0";
        }
        TempField = ReadField;
        TempValue = ReadValue;
        TempCompare = ReadCompare;

        if (mFieldMap == null) {
            mFieldMap = new ArrayList<>();
            AddMap(mFieldMap, "基础伤害", "0");
            AddMap(mFieldMap, "破体", "1");
            AddMap(mFieldMap, "破气", "2");
        }
    }

    @Override
    public String FilterGongfa(Gongfa gongfa){
        int type = gongfa.getType();
        Ability_Cuipo_Damage dmg = null;
        if ((type & GongfaType.TYPE_CUIPO) > 0) {
            dmg = ((Gongfa_Cuipo)gongfa).ability_cuipo_damage;
        }
        else
            return null;

        double editvalue = Double.parseDouble(ReadValue);
        String rt;
        int gfvalue = 0;        //功法内数据
        int edvalue = 0;        //用户填写的数据

        switch (ReadField)
        {
            case 0:
                gfvalue = (int)(dmg.Dmg * 10);
                rt = String.format("基础伤害: %.01f" , dmg.Dmg);
                edvalue = (int)(editvalue * 10);
                break;
            case 1:
                gfvalue = dmg.Poti;
                rt = String.format("破体: %d" , dmg.Poti);
                edvalue = (int)editvalue;
                break;
            case 2:
                gfvalue = dmg.Poqi;
                rt = String.format("破气: %d" , dmg.Poqi);
                edvalue = (int)editvalue;
                break;
            default:
                return null;
        }
        switch (ReadCompare)
        {
            case FC_EQUAL:
                if (gfvalue == edvalue) {
                    return rt;
                }
                else{
                    return null;
                }
            case FC_GREATER:
                if (gfvalue > edvalue) {
                    return rt;
                }
                else{
                    return null;
                }
            case FC_GREATERCONTAIN:
                if (gfvalue >= edvalue) {
                    return rt;
                }
                else {
                    return null;
                }
            case FC_SMALLER:
                if (gfvalue < edvalue) {
                    return rt;
                }
                else{
                    return null;
                }
            case FC_SMALLERCONTAIN:
                if (gfvalue <= edvalue) {
                    return rt;
                }
                else {
                    return null;
                }
            default:
                return null;
        }
    }
}
